package com.myblog.controller;

import com.myblog.annotation.Log;
import com.myblog.domain.GlobalResponse;
import com.myblog.services.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/article")
@Api(tags = "文章控制器")
public class ArticleController {

    @Resource
    ArticleService articleService;

    @GetMapping("/hotArticleList")
    @Log(BusinessName = "获取热门文章")
    @ApiOperation(value = "获取热门文章",notes = "获取前十阅读量文章")
    public GlobalResponse getHotArticleList(){
        return articleService.getHotArticleList();
    }

    @GetMapping("/articleList")
    @Log(BusinessName = "获取文章列表")
    @ApiOperation(value = "获取文章列表",notes = "获取按分页查询的文章列表")
    public GlobalResponse getArticleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.getArticleList(pageNum,pageSize,categoryId);
    }

    @GetMapping("/{id}")
    @Log(BusinessName = "获取文章")
    @ApiOperation(value = "获取具体文章",notes = "根据id获取具体文章")
    public GlobalResponse getArticle(@PathVariable("id") Long id) {
        return articleService.getArticle(id);
    }

    @PutMapping("updateViewCount/{id}")
    @Log(BusinessName = "更新文章浏览量")
    @ApiOperation(value = "更新文章浏览量",notes = "根据id获取文章浏览量")
    public GlobalResponse updateViewCount(@PathVariable("id") Long id){
        return  articleService.updateViewCount(id);
    }
}
